<?php


namespace App\backend\controllers\goods;


use App\backend\controllers\AdminBaseController;
use App\backend\models\GoodsModel;
use App\backend\services\GoodsDepotServices;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\Utils\JsonResp;

class GoodsDepotController extends AdminBaseController
{
    protected $class_name = 'GoodsDepot';

    /**
     * 商品回收站列表
     */
    public function getList(Request $request)
    {
        $data = $request->all();
        $validator = Validator::make(
            $data,
            GoodsModel::rules(),
            GoodsModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return JsonResp::error($msg[0]);
        }
        $list = GoodsDepotServices::getList($data);
        return JsonResp::success('成功', $list);
    }

    /**
     * 恢复回收站
     */
    public function goodsRestore(Request $request)
    {
        $data = $request->all();
        $validator = Validator::make(
            $data,
            GoodsModel::restore_rules(),
            GoodsModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return errorJson($msg[0], []);
        }
        $list = GoodsDepotServices::goodsRestore($data);
        if (!$list) {
            return errorJson('操作失败！', []);
        }
        return successJson('操作成功！', []);
    }

    /**
     * 删除商品回收站
     */
    public function goodsDelete(Request $request)
    {
        $data = $request->all();
        $validator = Validator::make(
            $data,
            GoodsModel::delete_rules(),
            GoodsModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return errorJson($msg[0], []);
        }
        $list = GoodsDepotServices::goodsDelete($data);
        return successJson('操作成功！', $list);
    }

}
